package com.qq.controller;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class MainMenu extends JFrame {


    JPanel userInfo_jPanel;
    JPanel friends_jPanel;


    public static void main(String[] args) {
        MainMenu mainMenu = new MainMenu();
    }

    public MainMenu() throws HeadlessException {
        this.setSize(300,600);
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        double screen_width = toolkit.getScreenSize().getWidth();
        this.setLocation((int)screen_width-400,50);
        // 创建好友以及消息列表
        initFriendsJPanel();

//        this.add(this.userInfo_jPanel);
        this.add(this.friends_jPanel);
        this.setVisible(true);
    }

    private void initFriendsJPanel(){
        this.friends_jPanel=new JPanel(new BorderLayout());

        JPanel tab = new JPanel(new FlowLayout(1,20,5));//选项卡面板
        JButton msg_btn = new JButton("消息");
        msg_btn.setSize(150,100);
        JButton contactPerson_btn = new JButton("联系人");
        contactPerson_btn.setSize(150,100);
        tab.add(msg_btn);
        tab.add(contactPerson_btn);

        JPanel listArea = new JPanel(new CardLayout());// 列表面板
        // 调用一个方法遍历用户的好友集合，生成好友列表(未实现)
        listArea.add(new JLabel("消息列表"),"messageList");
        listArea.add(new JLabel("好友列表"),"friendsList");
        CardLayout cards = (CardLayout) listArea.getLayout();
        msg_btn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                cards.show(listArea,"messageList");
            }
        });
        contactPerson_btn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                cards.show(listArea,"friendsList");
            }
        });




        this.friends_jPanel.add(tab,BorderLayout.NORTH);
        this.friends_jPanel.add(listArea,BorderLayout.CENTER);
    }

    private void initUserInfoJPanel(){
        this.userInfo_jPanel=new JPanel(new BorderLayout());


    }
}
